package com.um2.mauction.java;

import java.io.IOException;
import java.util.List;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import org.apache.struts.action.*;

import com.um2.mauction.session.impl.CategorieManagerBean;
import com.um2.mauction.session.impl.VenteManagerBean;
import com.um2.mauction.session.remote.CategorieManagerRemote;
import com.um2.mauction.session.remote.VenteManagerRemote;

public class FrmLogoffAction extends Action 
{
	public ActionForward execute(ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
	throws IOException, ServletException 
	{
		try {
			InitialContext ic = new InitialContext();
			CategorieManagerRemote cmanager = (CategorieManagerRemote)ic.lookup(CategorieManagerBean.RemoteJNDIName);
		
			List listeCategories = cmanager.getAllCategories();
			
			// Liste des ventes
			VenteManagerRemote vmanager = (VenteManagerRemote) ic.lookup(VenteManagerBean.RemoteJNDIName);
			List listeVentes = vmanager.getAllVentes();
			
			request.setAttribute("listeCategories",listeCategories);
			request.setAttribute("listeVentes",listeVentes);
			
			// Extract attributes we will need
			HttpSession session = request.getSession();
			// Remove user login
			session.removeAttribute("user");
		}
		catch(NamingException ex)
		{
			System.out.println("ERREUR!!" + ex.getMessage());
		}

		return mapping.findForward("index");
	}// end LogoffAction
}